/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ccore.instance.impl;

import ccore.common.impl.CElementImpl;

import ccore.instance.CObject;
import ccore.instance.InstancePackage;

import ccore.model.CClass;
import ccore.model.ModelPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>CObject</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ccore.instance.impl.CObjectImpl#getCClass <em>CClass</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class CObjectImpl extends CElementImpl implements CObject {
	/**
	 * The cached value of the '{@link #getCClass() <em>CClass</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCClass()
	 * @generated
	 * @ordered
	 */
	protected CClass cClass;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected CObjectImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return InstancePackage.Literals.COBJECT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CClass getCClass() {
		if (cClass != null && cClass.eIsProxy()) {
			InternalEObject oldCClass = (InternalEObject)cClass;
			cClass = (CClass)eResolveProxy(oldCClass);
			if (cClass != oldCClass) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, InstancePackage.COBJECT__CCLASS, oldCClass, cClass));
			}
		}
		return cClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CClass basicGetCClass() {
		return cClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetCClass(CClass newCClass, NotificationChain msgs) {
		CClass oldCClass = cClass;
		cClass = newCClass;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, InstancePackage.COBJECT__CCLASS, oldCClass, newCClass);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCClass(CClass newCClass) {
		if (newCClass != cClass) {
			NotificationChain msgs = null;
			if (cClass != null)
				msgs = ((InternalEObject)cClass).eInverseRemove(this, ModelPackage.CCLASS__COBJECTS, CClass.class, msgs);
			if (newCClass != null)
				msgs = ((InternalEObject)newCClass).eInverseAdd(this, ModelPackage.CCLASS__COBJECTS, CClass.class, msgs);
			msgs = basicSetCClass(newCClass, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InstancePackage.COBJECT__CCLASS, newCClass, newCClass));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case InstancePackage.COBJECT__CCLASS:
				if (cClass != null)
					msgs = ((InternalEObject)cClass).eInverseRemove(this, ModelPackage.CCLASS__COBJECTS, CClass.class, msgs);
				return basicSetCClass((CClass)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case InstancePackage.COBJECT__CCLASS:
				return basicSetCClass(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case InstancePackage.COBJECT__CCLASS:
				if (resolve) return getCClass();
				return basicGetCClass();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case InstancePackage.COBJECT__CCLASS:
				setCClass((CClass)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case InstancePackage.COBJECT__CCLASS:
				setCClass((CClass)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case InstancePackage.COBJECT__CCLASS:
				return cClass != null;
		}
		return super.eIsSet(featureID);
	}

} //CObjectImpl
